< previous page page_92 next page >

Page 92
Understanding Encapsulation
One of the most important pillars of object technology in achieving a solid separation of concerns is through encapsulation. In short, encapsulation is the separation of a class's interface from its internal, private implementation. Put in very real terms, you were created with a layer of skin over you to encapsulate your internal details, such as organs, veins, intestines, and so on. To use a more appetizing example, the information in the mail you receive is encapsulated from anyone's intimate knowledge (you hope) but yours. Sure, enough information is available on the external interface of the envelope (such as your name, address, city, state/province, and zip code) to route the envelope to you. However, the delivery person doesn't need to know what's inside the envelope in order to deliver it.
Classes, in general, must resemble the delivery person. No one class should be concerned with the internal details of another class. It should be concerned only with how to interact with a class's interface (like the information on the outside of an envelope). Encapsulation, then, contributes to the ease of an application's maintenance and evolution over time.
Encapsulation is often referred to as information hiding because of its goal of hiding internal information about the object and how it implements its class interface. Given that classes are abstractions, abstractions are only valid if they have achieved rock-solid encapsulation.
Let's quickly illustrate what this means. In Chapter 3, I discussed the following command button event:
cmdVerifyCheckAccountHistory_Click()
     theAccount.verifyCheckAccountHistory(SomeCustomerSSN)
End Sub
The command button, cmdVerifyCheckAccountHistory, is a member of the form object. No surprise there. However, because the form has knowledge of the object theAccount, the form subscribes to the theAccount object's verifyCheckAccountHistory method. That is, because the business activity of verifying checking account history is encapsulated in the theAccount object, the form was able to delegate the implementation of this operation to theAccount.
Understanding Inheritance
In general, Visual Basic doesn't support implementation inheritance, but it does enable you to use interface inheritance. Interface inheritance is the specializing of another class's interface for a particular context. Classes that implement the interface of another class share a unique relationship that can resemble a hierarchy or abstractions. In Booch

 
< previous page page_92 next page >

If you like this book, buy it!